<?php
$date = new DateTime($model->contractenddate);
$date->modify("+1 day");
$renewStartDate = $date->format("Y-m-d");
$date->modify("-1 day");
$date->modify("+1 year");
$renewEndDate = $date->format("Y-m-d");
$modelData = json_encode($model->attributes);
    /* @var $model Contracts */
    Yii::app()->clientScript->registerScript(
            'info', 
            "
            var contract = $modelData;
            var contractid='$model->contractid';
            var custno='$model->custno';
            var locno='$model->locno';
            var startDate='$model->contractstartdate';
            var endDate='$model->contractenddate';
            var renewStartDate='$renewStartDate';
            var renewEndDate='$renewEndDate';
            var renewBillType='$model->billtype';
            var renewContractType='$model->contractype';
            var renewBillingStatus = '4';
            ", 
            CClientScript::POS_HEAD
    );
/* @var $model Contracts */
?>
<?php Yii::app()->clientScript->registerScript('itemPriceCode', "itemPriceCode=''", CClientScript::POS_HEAD); ?>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/app/salesPortal/contractsUpdate.js', CClientScript::POS_BEGIN); ?>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/app/salesPortal/contractsNotes.js', CClientScript::POS_BEGIN); ?>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/app/salesPortal/contractsEquipment.js', CClientScript::POS_BEGIN); ?>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/app/salesPortal/contractsDoc.js', CClientScript::POS_BEGIN); ?>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/app/salesPortal/contractsQuote.js', CClientScript::POS_BEGIN); ?>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/app/salesPortal/contractsContacts.js', CClientScript::POS_BEGIN); ?>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/app/salesPortal/contractsZone.js', CClientScript::POS_BEGIN); ?>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/app/salesPortal/ContractsCellularMisc.js', CClientScript::POS_BEGIN); ?>
<?php
if($model->contractype == 4){
        
        Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/app/salesPortal/contractsSoftwareMaintLedger.js',  CClientScript::POS_BEGIN);
       // Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/app/softwareMaintRates.js',  CClientScript::POS_BEGIN);
    }
    Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/app/salesPortal/contractsEquipment.js', CClientScript::POS_BEGIN);
?>
<div id="left-col">
    <?php
    $this->renderPartial('_side', array(
        'action' => 'update',
        'contract' => $model,
        'customer' => $model->customer
    ));
    ?>
</div>

<div id="right-col">

    <div class="wrap">
        <div class="container">


            <div id="breadcrumb" style="display:none;"><span style="padding-left:10px;font-size:10px;color:#777777;"
                                                             id="alsoviewing"></span></div>
            <div class="inside">
                <h1>Contract # <?= $model->contractid; ?></h1>
                <?php
                $this->renderPartial('_form', array(
                    'model' => $model,
                ));
                ?>
                <div id="panel"></div>
                <ul id="tab" class="tabs tabs-with-summary">
                    <li class="active"><a id="tabNoteLink" href="#tabNote">Notes</a></li>
                    <li><a id="tabDocumentLink" href="#tabDocument">Documents</a></li>
                    <?php if($model->contractype==4):?>
                    <li><a id="tabNoteLink" href="#tabSoftwareMaintEquipment">Equipment</a></li>
                    <?php else:?>
                    <li><a id="tabNoteLink" href="#tabEq">Equipment</a></li>
                    <?php endif;?>
                    
                    
                    <li><a href="#tabBilling">Pre-Quote</a></li>
                    <li><a href="#tabQuarterly" id="quarterly">Quarterly</a></li>
                    <li><a href="#tabMonthly" id='monthly'>Monthly</a></li>
                    <li><a id="tabNoteLink" href="#tabAcc">Accounting</a></li>
                    <li class="alarm" style="display: none;"><a href="#tabZone">Alarm Zone</a></li>
                    <li class="alarm" style="display: none;"><a href="#tabCall">Alarm On-Call</a></li>
                    <li class="alarm" style="display: none;"><a href="#tabMiscSh">Monitoring Schedule</a></li>
                    <li class="alarm" style="display: none;"><a href="#tabMisc">Monitoring Misc</a></li>                    
                    <li class="cell" style="display: none;"><a href="#tabCell">Telguard Digital </a></li>
                </ul>
                <div id="tab1"></div>

                <div id="tabAcc">
                    <br/>
                    <script>
                        $(document).ready(function(){
                            $('#createQuote').click(function(e){
                                var href=$(this).attr('href');
                                window.location=href;
                                $(this).attr('href',null);
                            })
                        })
                    </script>
                    <a href="index.php?r=invoices/createContractQuote&contractid=<?= $model->contractid ?>" class="add-button" id="createQuote">Add Quote</a>
                    <?php
                    $this->renderPartial('/jobs/_invoicetable', array(
                        'quoteList' => $model->quoteList,
                        'salesOrderList' => $model->salesOrderList,
                        'invList' => $model->invoiceAndCMList
                    ));
                    ?>

                </div>
                <?php if($model->contractype == 4):?>
                    <div id="tabSoftwareMaintEquipment">
                        <br/>
                        <a href="javascript:void(0)" class="add-button" id="createItem">Add Equipment</a>
                        <div id="equipment-list" class="">

                        </div>
                        <br/>
                        <p>Software Maintenance Options</p>
                        <a href="javascript:void(0)" class="add-button" id="createSoft">Add Item</a>
                        <div id="soft-list"></div>
                    </div>
                <?php else:?>
                    <div id="tabEq">
                    
                        <br/>
                        <a href="javascript:void(0)" class="add-button" id="createItem">Add Equipment</a>
                        <div id="equipment-list" class="">

                        </div>
                    </div>
                <?php endif;?>
               
                <div id="tabNote">
                    <br/>
                    <a href="javascript:void(0)" class="add-button" id="createNote">Add Note</a>

                    <div id="notes-list" class="">

                    </div>
                </div>
                <div id="tabDocument">
                    <br/>
                    <iframe id="downloadFrame" src="" style="display:none;"></iframe>
                    <a class="add-button" href='javascript:void(0)' id="createJobDocument">Add Document</a>

                    <div id="document-list">

                    </div>
                </div>
                <div id='tabBilling'>
                    <br/>

                    <a href="javascript:void(0)" id="createQuoteItem" class="add-button">Add Item</a>
                    <?php 
                    echo CHtml::label('Discount', 'discount').'  ';
                    if($model->discounted) echo 'Enabled';
                        else
                    echo CHtml::dropDownList('discount', '0', array(0=>'No',1=>'Yes'),array('id'=>'inv_discount')); ?>
                    <br/>
                    <div id="quote-list" class="">
                    </div>
                    <div class="right-column" style="float:right;">

                        <table id="summarytable" style="width: 300px;text-align: right;float:right">


                            <tr>
                                <td>Material cost</td>
                                <td id="materialcost"></td>
                                <td>Subtotal</td>
                                <td id="subtotal"></td>


                            </tr>
                            <tr>

                                <td>Tax</td>
                                <td id="taxtotal">0.00</td>
                            </tr>
                            <tr>
                                <td>Other cost</td>
                                <td>0.00</td>
                                <td>Total</td>
                                <td id="total"></td>
                            </tr>
                            <tr>
                                <td>Gross Profit</td>
                                <td id="grossprofit"></td>
                            </tr>

                        </table>

                    </div>


                </div>
                <div id="tabQuarterly">
                    <br/>
                    <?php $this->renderPartial('_quarterlyForm', array('contract' => $model)); ?>
                </div>
                <div id="tabMonthly">
                    <br/>
                    <?php $this->renderPartial('_monthlyForm', array('contract' => $model)); ?>
                </div>
                <div id="tabZone">
                    <br/>
                    <a href="javascript:void(0)" class="add-button" id="createZone">Add Zone</a>

                    <div id="zone-list">

                    </div>
                </div>
                <div id="tabCall">
                    <br/>
                    <a href="javascript:void(0)" class="add-button" id="createContact">Add Contact</a>

                    <div id="call-list" class="">

                    </div>
                </div>
                <div id="tabMiscSh">
                    <?php echo $this->renderPartial('_sform', array('model' => $model));
                    ?>
                </div>
                <div id="tabMisc">
                    <br/>
                    <?php
                    echo $this->renderPartial('_miscform', array('model' => $model));
                    ?>
                </div>

                <div id="tabCell">
                    <br/>
                    <a href="javascript:void(0)" class="add-button" id="createCell">Add Subscriber</a>

                    <div id="cell-list" class="">

                    </div>
                </div>
                <!-- inside -->
            </div>
            <!-- container -->
        </div>
        <!-- wrap -->
        <?php $this->renderPartial('/copyright'); ?>
    </div>
    <!-- left-col -->
